﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain;
using MangoMes.Commont.Domain.SellStocks;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace ManagoMes.Read.API.Applications.SellStockSearchRead
{
    public class SellStockBackfillHandler : IRequestHandler<SellStockBackfillCommand, ResultsDTO<SellStockDTO>>
    {
        private readonly IBateRepository<SellStockDTO> _sellstockRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sellstockRepository"></param>
        public SellStockBackfillHandler(IBateRepository<SellStockDTO> sellstockRepository)
        {
            _sellstockRepository = sellstockRepository;
        }
        /// <summary>
        /// 销售出库单回填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO<SellStockDTO>> Handle(SellStockBackfillCommand request, CancellationToken cancellationToken)
        {
            DapperHelper dapper = new DapperHelper();
            var conn = dapper.MangoMesRead;
            var list = new ResultsDTO<SellStockDTO>() { Code = 0 };
            var str = "select * from sellstock inner join clientmanagement on sellstock.ClientId=clientmanagement.ClientId where sellstockId=" + request.SellStockId + "";
            var res = new SellStockDTO();
            list.Data = _sellstockRepository.GetAll(str, res, conn).ToList();
            return list;
        }
    }
}
